<?php
$url = 'localhost:3306';
$user = 'root';
$pwd = '';
$database = 'test';
$conn = mysqli_connect( $url, $user, $pwd, $database );
mysqli_query( $conn, 'set names utf8' );
$sql = 'select '.
' empno,ename,sal '.
' from emp';
$result = mysqli_query( $conn, $sql );
if ( $result ) {
    echo "查询到 " . mysqli_num_rows($result) . " 个员工<br>";
    // echo "<table border='1' >";
    // echo "<tr><th>编号</th><th>姓名</th><th>工资</th></tr>";
?>

<table border='1' >
<tr>
    <th>编号</th><th>姓名</th><th>工资</th>
</tr>

<?php
    while( $row = mysqli_fetch_assoc($result) ){
        // echo "编号=".$row["empno"] . ",姓名=".$row["ename"] . ",工资=".$row["sal"];
        // echo "<br>";
        // echo "<tr><td>".$row["empno"]."</td><td>".$row["ename"]."</td><td>".$row["sal"]."</td></tr>";
?>
<tr>
    <td><?= $row["empno"] ?></td>
    <td><?= $row["ename"] ?></td>
    <td><?= $row["sal"] ?></td>
</tr>
<?php
    }
    // echo "</table>";
?>
</table>
<?php
} else {
    echo '查询失败:' . mysqli_error( $conn );
}
mysqli_close( $conn );
?>